package com.chartboost.sdk.impl;

import android.content.Context;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import com.chartboost.sdk.Chartboost;
import com.chartboost.sdk.Libraries.CBOrientation.Difference;
import com.chartboost.sdk.Libraries.a.a;
import com.chartboost.sdk.Libraries.e.b;
import com.chartboost.sdk.b;
import com.chartboost.sdk.b.a;
import com.chartboost.sdk.b.b;
import com.chartboost.sdk.b.c;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;

public class h extends b
{
  private static int h = 50;
  private static int i = 50;
  private static int j = 30;
  private List<JSONObject> k = new ArrayList();
  private a.a l;
  private a.a m;
  private a.a n;
  private SparseArray<a.a> o;

  public h(a parama)
  {
    super(parama);
    this.e = 3;
  }

  protected b.b a(Context paramContext)
  {
    return new a(paramContext, null);
  }

  public void a(JSONObject paramJSONObject)
  {
    super.a(paramJSONObject);
    JSONArray localJSONArray = paramJSONObject.optJSONArray("cells");
    if (localJSONArray == null)
    {
      if (this.d != null)
        this.d.a();
      return;
    }
    this.o = new SparseArray();
    e.b local1 = new e.b()
    {
      public void a(a.a paramAnonymousa, Bundle paramAnonymousBundle)
      {
        h.e(h.this).put(paramAnonymousBundle.getInt("index"), paramAnonymousa);
        h.a(h.this, paramAnonymousa);
      }
    };
    int i1 = 0;
    if (i1 >= localJSONArray.length())
    {
      e.b local2 = new e.b()
      {
        public void a(a.a paramAnonymousa, Bundle paramAnonymousBundle)
        {
          h.b(h.this, paramAnonymousa);
          h.a(h.this, paramAnonymousa);
        }
      };
      e.b local3 = new e.b()
      {
        public void a(a.a paramAnonymousa, Bundle paramAnonymousBundle)
        {
          h.c(h.this, paramAnonymousa);
          h.a(h.this, paramAnonymousa);
        }
      };
      e.b local4 = new e.b()
      {
        public void a(a.a paramAnonymousa, Bundle paramAnonymousBundle)
        {
          h.d(h.this, paramAnonymousa);
          h.a(h.this, paramAnonymousa);
        }
      };
      a("close", local2);
      a("header-center", local3);
      a("header-tile", local4);
      return;
    }
    JSONObject localJSONObject1 = localJSONArray.optJSONObject(i1);
    this.k.add(localJSONObject1);
    String str = localJSONObject1.optString("type", "");
    if (str.equals("regular"))
    {
      JSONObject localJSONObject3 = localJSONObject1.optJSONObject("assets");
      if (localJSONObject3 != null)
      {
        this.e = (1 + this.e);
        Bundle localBundle3 = new Bundle();
        localBundle3.putInt("index", i1);
        a(localJSONObject3, "icon", local1, localBundle3);
      }
    }
    while (true)
    {
      i1++;
      break;
      if (str.equals("featured"))
      {
        JSONObject localJSONObject2 = localJSONObject1.optJSONObject("assets");
        if (localJSONObject2 != null)
        {
          this.e = (1 + this.e);
          Bundle localBundle1 = new Bundle();
          localBundle1.putInt("index", i1);
          a(localJSONObject2, "portrait", local1, localBundle1);
          this.e = (1 + this.e);
          Bundle localBundle2 = new Bundle();
          localBundle2.putInt("index", i1);
          a(localJSONObject2, "landscape", local1, localBundle2);
        }
      }
      else
      {
        str.equals("webview");
      }
    }
  }

  public void c()
  {
    super.c();
    this.k = null;
    this.l = null;
    this.n = null;
    this.m = null;
  }

  public class a extends b.b
  {
    private ImageView d;
    private ImageView e;
    private FrameLayout f;
    private q g;
    private t h;
    private t i;
    private a j;

    private a(Context arg2)
    {
      super(localContext);
      setBackgroundColor(-1842205);
      this.f = new FrameLayout(localContext);
      this.e = new ImageView(localContext);
      this.d = new ImageView(localContext);
      if (Chartboost.sharedChartboost().getForcedOrientationDifference().isOdd());
      for (int m = 0; ; m = 1)
      {
        this.g = new q(localContext, m);
        this.g.b().setBackgroundColor(-1842205);
        this.f.setFocusable(false);
        this.e.setFocusable(false);
        this.d.setFocusable(false);
        this.d.setClickable(true);
        this.h = new t(localContext, this.d);
        this.i = new t(localContext, this.f);
        addView(this.i);
        this.f.addView(this.e);
        addView(this.h);
        a(this.e);
        a(this.f);
        a(this.d);
        a(this.i);
        a(this.h);
        this.d.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            if (h.this.a != null)
              h.this.a.a();
          }
        });
        this.j = new a(localContext);
        return;
      }
    }

    private void a(View paramView)
    {
      int m = 200;
      if (m == getId())
        m = 201;
      View localView1 = findViewById(m);
      int n = m;
      for (View localView2 = localView1; ; localView2 = findViewById(n))
      {
        if (localView2 == null)
        {
          paramView.setId(n);
          paramView.setSaveEnabled(false);
          return;
        }
        n++;
      }
    }

    protected void a(int paramInt1, int paramInt2)
    {
      if (this.g.a() != null)
        removeView(this.g.a());
      FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-2, -2, 17);
      RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-2, -2);
      RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
      RelativeLayout.LayoutParams localLayoutParams3 = new RelativeLayout.LayoutParams(-2, -2);
      final CBOrientation.Difference localDifference = Chartboost.sharedChartboost().getForcedOrientationDifference();
      int m;
      int n;
      label120: int i1;
      label160: label309: int i2;
      label336: label485: int i3;
      if (localDifference.isOdd())
      {
        m = com.chartboost.sdk.Libraries.d.a(h.f(), getContext());
        localLayoutParams1.width = m;
        if (!localDifference.isOdd())
          break label632;
        n = -1;
        localLayoutParams1.height = n;
        switch (c()[localDifference.ordinal()])
        {
        default:
          BitmapDrawable localBitmapDrawable = new BitmapDrawable(h.b(h.this).b());
          localBitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
          localBitmapDrawable.setTileModeY(Shader.TileMode.CLAMP);
          this.f.setBackgroundDrawable(localBitmapDrawable);
          if (h.c(h.this) != null)
          {
            this.e.setImageBitmap(h.c(h.this).b());
            localLayoutParams.width = com.chartboost.sdk.Libraries.d.a(h.c(h.this).c(), getContext());
            localLayoutParams.height = com.chartboost.sdk.Libraries.d.a(Math.min(h.f(), h.c(h.this).d()), getContext());
          }
          this.d.setImageBitmap(h.d(h.this).b());
          if (localDifference.isOdd())
          {
            i1 = h.g();
            localLayoutParams2.width = com.chartboost.sdk.Libraries.d.a(i1, getContext());
            if (!localDifference.isOdd())
              break label675;
            i2 = h.h();
            localLayoutParams2.height = com.chartboost.sdk.Libraries.d.a(i2, getContext());
            switch (c()[localDifference.ordinal()])
            {
            default:
              localLayoutParams2.rightMargin = com.chartboost.sdk.Libraries.d.a(10, getContext());
              localLayoutParams2.topMargin = com.chartboost.sdk.Libraries.d.a((h.f() - h.g()) / 2, getContext());
              localLayoutParams2.addRule(11);
              label426: localLayoutParams3.width = -1;
              localLayoutParams3.height = -1;
              switch (c()[localDifference.ordinal()])
              {
              default:
                localLayoutParams3.addRule(3, this.i.getId());
                q localq = this.g;
                if (localDifference.isOdd())
                {
                  i3 = 0;
                  label502: localq.a(i3);
                  a(this.g.a());
                  this.g.a(this.j);
                  addView(this.g.a(), localLayoutParams3);
                  if (localDifference != CBOrientation.Difference.ANGLE_180)
                    break label872;
                  this.g.b().setGravity(80);
                }
                break;
              case 2:
              case 3:
              case 4:
              }
              break;
            case 2:
            case 3:
            case 4:
            }
          }
          break;
        case 2:
        case 3:
        }
      }
      while (true)
      {
        this.i.setLayoutParams(localLayoutParams1);
        this.e.setLayoutParams(localLayoutParams);
        this.e.setScaleType(ImageView.ScaleType.FIT_CENTER);
        this.h.setLayoutParams(localLayoutParams2);
        this.d.setScaleType(ImageView.ScaleType.FIT_CENTER);
        post(new Runnable()
        {
          public void run()
          {
            try
            {
              h.a.a(h.a.this, true);
              h.a.this.requestLayout();
              h.a.a(h.a.this).a().requestLayout();
              h.a.a(h.a.this).b().requestLayout();
              h.a.a(h.a.this, false);
              if ((localDifference == CBOrientation.Difference.ANGLE_180) || (localDifference == CBOrientation.Difference.ANGLE_90))
                h.a.a(h.a.this).c();
              return;
            }
            catch (Exception localException)
            {
            }
          }
        });
        return;
        m = -1;
        break;
        label632: n = com.chartboost.sdk.Libraries.d.a(h.f(), getContext());
        break label120;
        localLayoutParams1.addRule(11);
        break label160;
        localLayoutParams1.addRule(12);
        break label160;
        i1 = h.h();
        break label309;
        label675: i2 = h.g();
        break label336;
        localLayoutParams2.bottomMargin = com.chartboost.sdk.Libraries.d.a(10, getContext());
        localLayoutParams2.rightMargin = com.chartboost.sdk.Libraries.d.a((h.f() - h.g()) / 2, getContext());
        localLayoutParams2.addRule(11);
        localLayoutParams2.addRule(12);
        break label426;
        localLayoutParams2.leftMargin = com.chartboost.sdk.Libraries.d.a(10, getContext());
        localLayoutParams2.bottomMargin = com.chartboost.sdk.Libraries.d.a((h.f() - h.g()) / 2, getContext());
        localLayoutParams2.addRule(12);
        break label426;
        localLayoutParams2.topMargin = com.chartboost.sdk.Libraries.d.a(10, getContext());
        localLayoutParams2.leftMargin = com.chartboost.sdk.Libraries.d.a((h.f() - h.g()) / 2, getContext());
        break label426;
        localLayoutParams3.addRule(0, this.i.getId());
        break label485;
        localLayoutParams3.addRule(2, this.i.getId());
        break label485;
        localLayoutParams3.addRule(1, this.i.getId());
        break label485;
        i3 = 1;
        break label502;
        label872: if (localDifference == CBOrientation.Difference.ANGLE_90)
          this.g.b().setGravity(5);
        else
          this.g.b().setGravity(0);
      }
    }

    public void b()
    {
      super.b();
      this.d = null;
      this.e = null;
      this.g = null;
    }

    public class a extends ArrayAdapter<JSONObject>
    {
      Context a;

      public a(Context arg2)
      {
        super(0, h.a(h.this));
        this.a = localContext;
      }

      public JSONObject a(int paramInt)
      {
        return (JSONObject)h.a(h.this).get(paramInt);
      }

      public int getCount()
      {
        return h.a(h.this).size();
      }

      public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
      {
        CBOrientation.Difference localDifference = Chartboost.sharedChartboost().getForcedOrientationDifference();
        if (localDifference.isReverse())
          paramInt = -1 + getCount() - paramInt;
        final JSONObject localJSONObject = a(paramInt);
        String str = localJSONObject.optString("type", "");
        Object localObject;
        t localt;
        label88: c localc;
        if (paramView == null)
          if (str.equals("featured"))
          {
            localObject = new d(this.a);
            localt = new t(this.a, (View)localObject);
            ((h.b)localObject).a(localJSONObject, paramInt);
            localc = (c)localObject;
            if (!localDifference.isOdd())
              break label261;
            localt.setLayoutParams(new AbsListView.LayoutParams(((h.b)localObject).a(), -1));
          }
        while (true)
        {
          View.OnClickListener local1 = new View.OnClickListener()
          {
            public void onClick(View paramAnonymousView)
            {
              String str = localJSONObject.optString("deep-link");
              if ((str == null) || (str.equals("")))
                str = localJSONObject.optString("link");
              if (h.this.b != null)
                h.this.b.a(str, localJSONObject);
            }
          };
          localc.a = local1;
          localc.setOnClickListener(local1);
          if ((localObject instanceof e))
            ((e)localObject).b.setOnClickListener(local1);
          return localt;
          if (str.equals("regular"))
          {
            localObject = new e(this.a);
            break;
          }
          boolean bool = str.equals("webview");
          localObject = null;
          if (!bool)
            break;
          localObject = new i(this.a);
          break;
          localt = (t)paramView;
          localObject = (h.b)localt.a();
          break label88;
          label261: localt.setLayoutParams(new AbsListView.LayoutParams(-1, ((h.b)localObject).a()));
        }
      }
    }
  }

  public static abstract interface b
  {
    public abstract int a();

    public abstract void a(JSONObject paramJSONObject, int paramInt);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.chartboost.sdk.impl.h
 * JD-Core Version:    0.6.2
 */